if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
import DrawModel from '../Model/DrawModel';
import { TipsView } from './TipsView';
let context = getContext(this);
export class ChartView extends ViewPU {
    constructor(q10, r10, s10, t10 = -1, u10 = undefined, v10) {
        super(q10, s10, t10, v10);
        if (typeof u10 === "function") {
            this.paramsGenerator_ = u10;
        }
        this.settings = new RenderingContextSettings(true);
        this.canvasContext = new CanvasRenderingContext2D(this.settings);
        this.drawModel = new DrawModel(this.canvasContext);
        this.lastDownX = 0;
        this.onSelected = undefined;
        this.__dataSource = new SynchedPropertyObjectTwoWayPU(r10.dataSource, this, "dataSource");
        this.__screenWidth = new ObservedPropertySimplePU(350, this, "screenWidth");
        this.__screenHeight = new ObservedPropertySimplePU(0, this, "screenHeight");
        this.__tipsDesc = new SynchedPropertySimpleOneWayPU(r10.tipsDesc, this, "tipsDesc");
        this.__legend = new SynchedPropertyObjectOneWayPU(r10.legend, this, "legend");
        this.__selectedIndex = new SynchedPropertySimpleTwoWayPU(r10.selectedIndex, this, "selectedIndex");
        this.setInitiallyProvidedValue(r10);
        this.declareWatch("dataSource", this.refresh);
        this.declareWatch("selectedIndex", this.updateHighlightIndex);
        this.finalizeConstruction();
    }
    setInitiallyProvidedValue(p10) {
        if (p10.settings !== undefined) {
            this.settings = p10.settings;
        }
        if (p10.canvasContext !== undefined) {
            this.canvasContext = p10.canvasContext;
        }
        if (p10.drawModel !== undefined) {
            this.drawModel = p10.drawModel;
        }
        if (p10.lastDownX !== undefined) {
            this.lastDownX = p10.lastDownX;
        }
        if (p10.onSelected !== undefined) {
            this.onSelected = p10.onSelected;
        }
        if (p10.screenWidth !== undefined) {
            this.screenWidth = p10.screenWidth;
        }
        if (p10.screenHeight !== undefined) {
            this.screenHeight = p10.screenHeight;
        }
    }
    updateStateVars(o10) {
        this.__tipsDesc.reset(o10.tipsDesc);
        this.__legend.reset(o10.legend);
    }
    purgeVariableDependenciesOnElmtId(n10) {
        this.__dataSource.purgeDependencyOnElmtId(n10);
        this.__screenWidth.purgeDependencyOnElmtId(n10);
        this.__screenHeight.purgeDependencyOnElmtId(n10);
        this.__tipsDesc.purgeDependencyOnElmtId(n10);
        this.__legend.purgeDependencyOnElmtId(n10);
        this.__selectedIndex.purgeDependencyOnElmtId(n10);
    }
    aboutToBeDeleted() {
        this.__dataSource.aboutToBeDeleted();
        this.__screenWidth.aboutToBeDeleted();
        this.__screenHeight.aboutToBeDeleted();
        this.__tipsDesc.aboutToBeDeleted();
        this.__legend.aboutToBeDeleted();
        this.__selectedIndex.aboutToBeDeleted();
        SubscriberManager.Get().delete(this.id__());
        this.aboutToBeDeletedInternal();
    }
    get dataSource() {
        return this.__dataSource.get();
    }
    set dataSource(m10) {
        this.__dataSource.set(m10);
    }
    get screenWidth() {
        return this.__screenWidth.get();
    }
    set screenWidth(l10) {
        this.__screenWidth.set(l10);
    }
    get screenHeight() {
        return this.__screenHeight.get();
    }
    set screenHeight(k10) {
        this.__screenHeight.set(k10);
    }
    get tipsDesc() {
        return this.__tipsDesc.get();
    }
    set tipsDesc(j10) {
        this.__tipsDesc.set(j10);
    }
    get legend() {
        return this.__legend.get();
    }
    set legend(i10) {
        this.__legend.set(i10);
    }
    get selectedIndex() {
        return this.__selectedIndex.get();
    }
    set selectedIndex(h10) {
        this.__selectedIndex.set(h10);
    }
    aboutToAppear() {
        this.drawModel.onSelected((g10) => {
            if (this.onSelected) {
                this.onSelected(g10);
            }
        });
    }
    updateHighlightIndex() {
        this.drawModel.setHighlightIndex(this.selectedIndex);
        this.drawModel.initMoveLineCurX();
        this.draw();
    }
    refresh() {
        this.drawModel.setDataSource(this.dataSource);
        this.draw();
    }
    draw() {
        this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight);
    }
    initialRender() {
        this.observeComponentCreation2((d10, e10) => {
            Column.create();
        }, Column);
        this.observeComponentCreation2((z9, a10) => {
            Row.create();
            Row.onAppear(() => {
                const c10 = JSON.parse(getInspectorByKey('container'))
                    .$attrs
                    .size;
                this.screenWidth = Number(c10.width.split('v')[0]);
                this.screenHeight = Number(c10.height.split('v')[0]);
            });
            Row.id('container');
        }, Row);
        this.observeComponentCreation2((x9, y9) => {
            Column.create();
            Column.width('100%');
        }, Column);
        this.observeComponentCreation2((p9, q9) => {
            Canvas.create(this.canvasContext);
            Canvas.width(this.screenWidth);
            Canvas.height(250);
            Canvas.onReady(() => {
                setTimeout(() => {
                    this.updateHighlightIndex();
                }, 0);
            });
            Canvas.onTouch((t9) => {
                if (t9.type === TouchType.Down) {
                    this.lastDownX = t9.touches[0].x;
                    this.drawModel.setMoveLineCur(this.lastDownX, 'move');
                }
                if (t9.type === TouchType.Move) {
                    let v9 = t9.touches[0].x;
                    this.drawModel.setMoveLineCur(v9, 'move');
                    this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight);
                }
                if (t9.type === TouchType.Up) {
                    let u9 = t9.touches[0].x;
                    this.drawModel.setMoveLineCur(u9, 'up');
                    this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight);
                }
            });
        }, Canvas);
        Canvas.pop();
        Column.pop();
        Row.pop();
        {
            this.observeComponentCreation2((j9, k9) => {
                if (k9) {
                    let l9 = new TipsView(this, { tipsDesc: this.tipsDesc, legend: this.legend }, undefined, j9, () => { }, { page: "common/public/src/main/ets/components/EcChart/view/ChartView.ets", line: 105 });
                    ViewPU.create(l9);
                    let m9 = () => {
                        return {
                            tipsDesc: this.tipsDesc,
                            legend: this.legend
                        };
                    };
                    l9.paramsGenerator_ = m9;
                }
                else {
                    this.updateStateVarsOfChildByElmtId(j9, {
                        tipsDesc: this.tipsDesc, legend: this.legend
                    });
                }
            }, { name: "TipsView" });
        }
        Column.pop();
    }
    rerender() {
        this.updateDirtyElements();
    }
}
